<?php
/*
 * Created on Nov 4, 2007
 *
 * Continut:
 *
 */

function showLeftSideSectionElements(){
	if(isset($_GET['leftMenu'])){
		switch ($_GET['leftMenu']){
			case 'editor':
				showLeftSideEditorMenu();
				break;

			case 'parteneri':
				showLeftSideParteneriMenu();
				break;

			case 'chat':
				showLeftSideChatMenu();
				break;
		}
	}
}

function showLeftSideEditorMenu(){
	echo("<!-- **Editor** -->");
	///echo("<tr><td>Editor</td></tr>");

	echo("<!-- File -->");
	echo("<tr id='file' onclick=\"hideElements(this.id, 'anunturi')\">");
	echo("<td class='caption'>File</td>");
	echo("<input type='hidden' id='fileNrElems' value='4' /></tr>");
	echo("<tr class='hidden'><td class='add'><a href='index.php?leftMenu=editor&center=newproj'>   New...  </a></td></tr>");
	echo("<tr class='hidden'><td class='add'><a href='index.php?leftMenu=editor&center=openproj'>   Open...  </a></td></tr>");
	echo("<tr class='hidden'><td class='add'><a href='index.php?print=1&chapter=".$_GET['chapter']."' target='_blank'>   Export...  </a></td></tr>");
	echo("<tr class='hidden'><td class='last add'><a href='#'>Save changes</a></td></tr>");

	echo("<!-- Toolbox -->");
	echo("<tr id='toolbox' onclick=\"hideElements(this.id, 'anunturi')\">");
	echo("<td class='caption'>Toolbox</td>");
	echo("<input type='hidden' id='toolboxNrElems' value='3' /></tr>");
	echo("<tr class='hidden'><td class='add'><a href='#'>   Capitol  </a></td></tr>");
	echo("<tr class='hidden'><td class='add'><a href='#'>   Print preview  </a></td></tr>");
	echo("<tr class='hidden'><td class='last add'><a href='#'>Sterge...</a></td></tr>");

	echo("<!-- Content -->");
	echo("<tr id='docContent' onclick=\"hideElements(this.id, 'anunturi')\">");
	echo("<td class='caption'>Content</td>");
	readDocChapters();
}

function showLeftSideParteneriMenu(){
	echo("<!-- **Parteneri** -->");
	//echo("<tr><td>Parteneri</td></tr>");

	echo("<!-- Agenda -->");
	echo("<tr id='agenda' onclick=\"hideElements(this.id, 'anunturi')\">");
	echo("<td class='caption'>Agenda</td>");
	echo("<input type='hidden' id='agendaNrElems' value='3' /></tr>");
	echo("<tr class='hidden'><td class='add'><a href='#'>   Add friend  </a></td></tr>");
	echo("<tr class='hidden'><td class='add'><a href='index.php?leftMenu=parteneri&center=viewAgenda'>   View  </a></td></tr>");
	//	echo("<tr class='hidden'><td class='add'><a href='#'>   Import  </a></td></tr>");
	echo("<tr class='hidden'><td class='last add'><a href='index.php?leftMenu=parteneri&center=export'>Export</a></td></tr>");

	 echo("<!-- Invitatii -->");
	 echo("<tr id='documente' onclick=\"hideElements(this.id, 'anunturi')\">");
	 echo("<td class='caption'>Invitatii</td>");
	 echo("<input type='hidden' id='documenteNrElems' value='3' /></tr>");
	 echo("<tr class='hidden'><td class='add'><a href='#'>   +++++  </a></td></tr>");
	 echo("<tr class='hidden'><td class='add'><a href='#'>   +++++  </a></td></tr>");
	 echo("<tr class='hidden'><td class='last add'><a href='#'>   +++++  </a></td></tr>");

/* echo("<!-- Comentarii -->");
	 echo("<tr id='comentarii' onclick=\"hideElements(this.id, 'anunturi')\">");
	 echo("<td class='caption'>Comentarii</td>");
	 echo("<input type='hidden' id='comentariiNrElems' value='2' /></tr>");
	 echo("<tr class='hidden'><td class='add'><a href='#'>Add</a></td></tr>");
	 echo("<tr class='hidden'><td class='last add'><a href='#'>Remove</a></td></tr>");*/
}

function showLeftSideChatMenu(){
	echo("<!-- Chat Grups-->");
	echo("<tr id='chatGroups' onclick=\"hideElements(this.id, 'anunturi')\">");
	echo("<td class='caption'>Grups</td>");

	$dom=new DOMDocument();
	$dom->load("xmlDb/userProjects.xml");
	$xsl=new DOMDocument();
	$xsl->load("include/xsl/openProjListFriends.xsl");
	$proc=new XSLTProcessor();
	$proc->importStylesheet($xsl);
	$proc->setParameter("", "username", $_SESSION['username']);
	$prj=explode(";",rtrim($proc->transformToXml($dom)));
	array_pop($prj);
	$nrElem=count($prj);
	echo("<input type='hidden' id='chatGroupsNrElems' value='".$nrElem."' /></tr>");
	for($i=0; $i<$nrElem; $i++){
		if($i == $nrElem){
			echo("<tr class='hidden'><td class='last add'><a href='#'>".$prj[$i]."</a></td></tr>");
		}else{
			echo("<tr class='hidden'><td class='add'><a href='#'>".$prj[$i]."</a></td></tr>");
		}
	}
	
	unset($dom);
	unset($xsl);
	unset($proc);

	//echo("<input type='hidden' id='chatGroupsNrElems' value='1' /></tr>");
	//echo("<tr class='hidden'><td class='last add'><a href='#'>Grup nr.1</a></td></tr>");

	echo("<!-- Chat Personal-->");
	/*	echo("<tr id='chatPersonal' onclick=\"hideElements(this.id, 'anunturi')\">");
	 echo("<td class='caption'>Personal</td>");
	 echo("<input type='hidden' id='chatPersonalNrElems' value='1' /></tr>");
	 echo("<tr class='hidden'><td class='last add'><a href='#'>Friend 1</a></td></tr>");*/
	$dom=new DOMDocument();
	$dom->load("xmlDb/agenda.xml");
	$xsl=new DOMDocument();
	$xsl->load("include/xsl/chatListFriends.xsl");
	$proc=new XSLTProcessor();
	$proc->importStylesheet($xsl);
	$proc->setParameter("", "username", $_SESSION['username']);
	print $proc->transformToXml($dom);
}

function readDocChapters(){
	//2. incarcare elemente in meniul Content__se realiz la incarcare pagina
	if(isset($_SESSION['docName']) && isset($_SESSION['docPath'])){
	//echo $_SESSION['docPath'];
		$doc=new xmlDocument($_SESSION['docName'], $_SESSION['docPath']);
		//echo $_SESSION['docName']."++".$_SESSION['docPath'];
		$_SESSION['documentInfo']=$chapters=$doc->getAllChapters();
		//var_dump($_SESSION['documentInfo']);
			
		$chapterInfo=array_values($chapters);
		$chapterKeys=array_keys($chapters);
		//var_dump($chapterNames);
		$elems=count($chapters);
		$contor=$elems+1;
		echo("<input type='hidden' id='docContentNrElems' value='".$contor."' /></tr>");
		if($contor ==1){
			echo("<tr class='hidden'><td class='last add'><a href='index.php?leftMenu=editor&center=view&chapter=docInfo'>   DocInfo  </a></td></tr>");
		}else {
			echo("<tr class='hidden'><td class='add'><a href='index.php?leftMenu=editor&center=view&chapter=docInfo'>   DocInfo  </a></td></tr>");
		}
		for ($i=0;$i<$elems;$i++){
			if($i !== ($elems-1)){
				echo("<tr class='hidden'><td class='add'><a href='index.php?leftMenu=editor&center=view&chapter=".$chapterKeys[$i]."'>   ".$chapterInfo[$i]['title']."  </a></td></tr>");
			}else {
				echo("<tr class='hidden'><td class='last add'><a href='index.php?leftMenu=editor&center=view&chapter=".$chapterKeys[$i]."'>   ".$chapterInfo[$i]['title']."  </a></td></tr>");
			}
		}
	}else {
		echo("<input type='hidden' id='docContentNrElems' value='0' /></tr>");
	}
}
?>
